<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <div th:replace="common/commonVant::commonStaticVant"></div>
    <script th:src="@{/common/localStorage.js}"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta charset="UTF-8">
    <title th:text="${title}+'相关文章'"></title>
</head>
<body>
<div id="app" v-cloak>
    <van-pull-refresh v-model="refreshing" :head-height="80" @refresh="refresh">
        <template #pulling="props">
            <van-image src="http://localhost/images/small.jpg" class="loadingImg"/>
        </template>
        <template #loosing>
            <van-image src="http://localhost/images/small.jpg" class="loadingImg"/>
        </template>
        <template #loading>
            <van-image src="http://localhost/images/small.jpg" class="loadingImg"/>
        </template>
        <transition name="van-fade">
            <div>
                <van-cell-group v-show="articleList.length>0">
                    <van-cell v-for="(item,index) in articleList" :key="index"
                              is-link @click="toArticleDetail(item.id)"/>
                    <template #title>
                        <span class="custom-title">{{item.articleTitle}}</span>
                        <van-icon name="fire-o" v-if="item.hot==1" color="red"/>
                    </template>
                    <template #label>
                        <div class="van-multi-ellipsis--l2">{{item.articleContent}}</div>
                    </template>
                </van-cell-group>
                <van-empty description="暂无更多数据" v-show="articleList.length==0">
                    <van-button type="primary" @click="resetRefresh">
                        重置
                    </van-button>
                </van-empty>
            </div>
        </transition>
    </van-pull-refresh>
</div>
<script th:inline="javascript">
    let mvvm = new Vue({
        el: '#app',
        data: {
            refreshing: false,
            token: '',
            getArticlePageParam: {
                pageCurrent: 1,
                pageSize: 10,
                tabName: [[${title}]]
            },
            articleList: [],
        },
        methods: {
            async getArticlePage() {
                const result = await httpPost("/article/selectArticleByTabContent", this.getArticlePageParam);
                if (result.code == 200) {
                    this.refreshing = false;
                    this.articleList = result.data.records;
                }
            },
            refresh() {
                this.getArticlePageParam.pageCurrent++;
                this.getArticlePage();
            },
            resetRefresh() {
                this.getArticlePageParam.pageSize = 10;
                this.getArticlePageParam.pageCurrent = 1;
                this.getArticlePage();
            },
            toArticleDetail(id) {
                window.location.href = [[${#request.getContextPath()}]] + '/home/articleDetail/' + id;
            },

        },
        mounted() {
            this.getArticlePage();
        }
    })
</script>
<style>
    .loadingImg{
        width: 200px;
        height: 72px;
        margin-top: 8px;
        border-radius: 4px;
    }
</style>
</body>
</html>